package com.javaDemo.ti;

import java.util.Arrays;

public class Dizengzixulei {
    public static void main(String[] args) {
        int[] nums={10,9,2,5,3,7,101,18};
        int[] dp=new int[nums.length];
        int count=0;
        for(int i=0;i<nums.length-1;i++){
            for(int j=i+1;j<nums.length;j++){
                if(nums[j]>=nums[i]){
                    dp[j]= Math.max(dp[j],dp[i]+1);
                }
                count = Math.max(count, dp[j]);
            }
        }
        System.out.println(count);

        //最长连续子序列
        Arrays.fill(dp, 1);//以某一值为结尾，那么长度至少是1
        int result = 1;//保存结果
        //递推
        for(int i = 1; i < nums.length; i++) {
            for(int j = 0; j < i; j++) {
                if(nums[j] < nums[i]) {//注意前是递增的序列才被比较添加
                    dp[i] = Math.max(dp[j] + 1, dp[i]);
                }
            }
            result = Math.max(dp[i], result);
        }
        count= dp[nums.length - 1];
        System.out.println(count);

        //最长连续子数组
        Arrays.fill(dp, 1);
        for(int i = 1; i < nums.length; i++) {
            if(nums[i - 1] < nums[i]) {
                dp[i] = dp[i - 1] + 1;
            }
            if(dp[i] > result) {
                result = dp[i];
            }
        }
        System.out.println(result);

    }



}